//
//  QP_CleanCachesGroup.m
//  A_project2.0
//
//  Created by Tiny on 16/3/15.
//  Copyright © 2016年 七平. All rights reserved.
//

#import "QP_CleanCachesGroup.h"

@implementation QP_CleanCachesGroup

#pragma mark - 清理方法
+ (void)clean:(NSString *)path
{
    NSArray *files = [[NSFileManager defaultManager]subpathsAtPath:path];
    for (NSString *p in files) {
        NSError *error;
        NSString *pathstr= [path stringByAppendingPathComponent:p];
        if ([[NSFileManager defaultManager] fileExistsAtPath:pathstr]) {
            [[NSFileManager defaultManager] removeItemAtPath:pathstr error:&error];
        }
    }
}
#pragma mark - 文件夹计算大小方法 遍历文件夹获得文件夹大小 返回多少MB
+ (float) folderSizeAtPath:(NSString *)folderPath
{
    NSFileManager *manager = [NSFileManager defaultManager];
    if (![manager fileExistsAtPath:folderPath])
        return 0;
    
    NSEnumerator *childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    
    NSString* fileName;
    
    long long folderSize = 0;
    
    while ((fileName = [childFilesEnumerator nextObject]) != nil){
        
        NSString* fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        
        folderSize += [self fileSizeAtPath:fileAbsolutePath];
        
    }
    
    return folderSize/(1024.0*1024.0);
    
    
}

+ (long long) fileSizeAtPath:(NSString*) filePath{
    
    NSFileManager* manager = [NSFileManager defaultManager];
    
    if ([manager fileExistsAtPath:filePath]){
        
        return [[manager attributesOfItemAtPath:filePath error:nil] fileSize];
        
    }
    
    return 0;
    
}

@end
